
<template>
  
  <view class="container">
	  <view class="serBox">
	  		  <view class="title">姓名：</view>
	  		  <u--input
	  		      placeholder="请输入姓名"
	  		      border="surround"
	  		      clearable
	  				v-model="form.studentName"
	  		    >
	  		  </u--input>
	  </view>
	  <view class="serBox">
	  		  <view class="title">性别：</view>
	  		  <u--input
	  		      placeholder="请选择性别"
	  		      border="surround"
	  		      clearable
	  			  disabled
	  				v-model="form.studentSex1"
	  		    >
	  		  </u--input>
	  		<u-button style="width: 20%;" type="success" @tap="getXb" text="请选择"></u-button>
	  </view>
	  <view class="serBox">
	  		  <view class="title">出生日期：</view>
	  		  <u--input
	  		      placeholder="请选择出生日期"
	  		      border="surround"
	  		      clearable
	  			  disabled
	  			  v-model="form.studentBirth"
	  		    >
	  		  </u--input>
	  		<u-button style="width: 20%;" type="success" @tap="getRq" text="请选择"></u-button>
	  </view>
	  <view class="serBox">
	  		  <view class="title">身份证号：</view>
	  		  <u--input
	  		      placeholder="请输入身份证号"
	  		      border="surround"
	  		      clearable
	  				v-model="form.idCard"
	  		    >
	  		  </u--input>
	  </view>
	  <view class="serBox">
	  		  <view class="title">民族：</view>
	  		  <u--input
	  		      placeholder="请选择民族"
	  		      border="surround"
	  		      clearable
	  			  disabled
	  				v-model="form.studentNation1"
	  		    >
	  		  </u--input>
	  		<u-button style="width: 20%;" type="success" @tap="getMz" text="请选择"></u-button>
	  </view>
	  <view class="serBox">
	  		  <view class="title">家庭住址：</view>
	  		  <u--input
	  		      placeholder="请输入家庭住址"
	  		      border="surround"
	  		      clearable
	  				v-model="form.studentNative"
	  		    >
	  		  </u--input>
	  </view>
	  
	  <view class="serBox">
		  <view class="title">学校信息：</view>
		  <u--input
		      placeholder="请选择学校信息"
		      border="surround"
		      clearable
			  disabled
			  v-model="form.classId1"
		    >
		  </u--input>
		  <u-button style="width: 20%;" type="success" @tap="getSC" text="请选择"></u-button>
	  </view>
	  <button v-if='adShow' @tap='submit()' class="submit-button" >新增</button>
	  <button v-if='edShow' @tap='edit()' class="submit-button" >修改</button>
	 <u-datetime-picker
			  :show="csrqshow"
			  v-model="form.studentBirth"
			  mode="date"
			  :min-date="minDate"
			  ref="datetimePicker"
			  :formatter='formatter'
			  @confirm = 'dateConfirm'
	  ></u-datetime-picker>
	  <u-picker :show="scjdshow" :columns="jdList" @cancel='scjdshow = false' @confirm="confirmJD" keyName="label"></u-picker>
	  <u-picker @cancel='jdshow = false' @confirm='jdconfirm' :show="jdshow" :columns="jdcolumns" keyName="label"></u-picker>
	  <u-picker :show="xbshow" :columns="xbList" @cancel='xbshow = false' @confirm="confirmXB" keyName="label"></u-picker>
	  <u-picker :show="mzshow" :columns="mzList" @cancel='mzshow = false' @confirm="confirmMZ" keyName="label"></u-picker>
  </view>
</template>

<script>
	import {
			getDicts
		} from '@/api/system/dict/data.js'
	import { addFilesStudent,updateFilesStudent } from "@/api/files/screenPlanInfo"; 
	 import { listFilesStudent} from "@/api/files/filesStudent";
  export default {
    data() {
      return {
		  minDate: new Date(new Date().getFullYear() - 23, 0, 1).getTime(),
		  edShow:false,
		  adShow:false,
		  formatter(type, value) {
		  	if (type === 'year') {
		  		return `${value}年`
		  	}
		  	if (type === 'month') {
		  		return `${value}月`
		  	}
		  	if (type === 'day') {
		  		return `${value}日`
		  	}
		  	return value
		  },
		  mzList:[],
		  mzshow:false,
		  csrqshow:false,
		  xbList:[],
		  xbshow:false,
		  form:{
			  // studentBirth:Number(new Date()),
		  },
		  date: '2024', // 默认选中的日期
		  scndshow:false,
		  scjdshow:false,
		  jdshow:false,
		  ndshow:false,
		  jdcolumns:[
			  [{
				  label: '未完成',
				  id: 0
			  }, {
				  label: '已完成',
				  id: 1
			  }]
		  ],
		  jdList:[],
		  itemData:{},
		  bmshow: false,
		  tips:'请选择',
		  jhList:[],
		  queryParams: {
			  pageNum: 1,
			  pageSize: 200,
			  // result1:'未完成',
			  // result:0,
			  planYear:'2024'
			},
      }  
    },
	onShow() {
		let pages = getCurrentPages();
		if (pages[pages.length - 1].$vm.deptData) {
			this.itemData = pages[pages.length - 1].$vm.deptData
			this.form.classId = this.itemData.id
			this.form.classId1 = this.itemData.label
			this.$forceUpdate()
			// this.getList()
		}
	  },
	onLoad(e) {  
		if(e.studentId){
			this.edShow = true
			let obj={
				pageNum:1,
				pageSize:1,
				studentId:e.studentId
			}
			listFilesStudent(obj).then(res=>{
				this.form = res.rows[0]
			})
		}else{
			this.adShow = true
		}
		// this.getList()
		getDicts('files_nation').then(res=>{
			let arr = []
			var data=res.data
			for(let i=0;i<data.length;i++){
			   arr[i]={
					 label:data[i].dictLabel,
					 id:data[i].dictValue
				 }
			 }
			 this.mzList = [arr]
		})
		getDicts('files_sex').then(res=>{
			let arr = []
			var data=res.data
			for(let i=0;i<data.length;i++){
			   arr[i]={
					 label:data[i].dictLabel,
					 id:data[i].dictValue
				 }
			 }
			 this.xbList = [arr]
		})
		getDicts('plan_quarter').then(res=>{
			let arr = []
			var data=res.data
			for(let i=0;i<data.length;i++){
			   arr[i]={
					 label:data[i].dictLabel,
					 id:data[i].dictValue
				 }
			 }
			 this.jdList = [arr]
		})
	},
	methods:{
		dateConfirm(e){
			let datee = uni.$u.timeFormat(e.value, 'yyyy-mm-dd')
			// console.log(datee,'datee')
			this.$nextTick(()=>{
				this.form.studentBirth = datee
				this.csrqshow = false
			})
			
			this.$forceUpdate()
		},
		submit(){
			if(!this.form.studentName){
				uni.showToast({
					title: '请输入姓名',
					icon:'none',
					duration:850
				});
				return
			}
			if(!this.form.studentSex){
				uni.showToast({
					title: '请选择性别',
					icon:'none',
					duration:850
				});
				return
			}
			if(!this.form.studentBirth){
				uni.showToast({
					title: '请选择出生日期',
					icon:'none',
					duration:850
				});
				return
			}
			if(!this.form.idCard){
				uni.showToast({
					title: '请输入身份证号',
					icon:'none',
					duration:850
				});
				return
			}
			if(!this.form.classId){
				uni.showToast({
					title: '请选择学校信息',
					icon:'none',
					duration:850
				});
				return
			}
			addFilesStudent(this.form).then(res=>{
				uni.navigateBack(
					{delta:1}
				)
			}).catch(err=>{
				uni.showToast({
					title: '新增失败',
					icon:'none',
					duration:850
				});
				return
			})
		},
		edit(){
			if(!this.form.studentName){
				uni.showToast({
					title: '请输入姓名',
					icon:'none',
					duration:850
				});
				return
			}
			if(!this.form.studentSex){
				uni.showToast({
					title: '请选择性别',
					icon:'none',
					duration:850
				});
				return
			}
			if(!this.form.studentBirth){
				uni.showToast({
					title: '请选择出生日期',
					icon:'none',
					duration:850
				});
				return
			}
			if(!this.form.idCard){
				uni.showToast({
					title: '请输入身份证号',
					icon:'none',
					duration:850
				});
				return
			}
			if(!this.form.classId){
				uni.showToast({
					title: '请选择学校信息',
					icon:'none',
					duration:850
				});
				return
			}
			updateFilesStudent(this.form).then(res=>{
				uni.navigateBack(
					{delta:1}
				)
			}).catch(err=>{
				uni.showToast({
					title: '修改失败',
					icon:'none',
					duration:850
				});
				return
			})
		},
		getXb(){
			this.xbshow = true
		},
		getRq(){
			this.csrqshow = true
		},
		getMz(){
			this.mzshow = true
		},
		bindDateChange(e){
			this.date = e.target.value.substr(0, 4);
			this.queryParams.planYear = e.target.value.substr(0, 4);
			this.getList()
		},
		confirmJD(e){
			this.queryParams.planQuarter2 = e.value[0].label
			this.queryParams.planQuarter = e.value[0].id
			this.scjdshow = false
			this.getList()
		},
		confirmXB(e){
			this.form.studentSex1 = e.value[0].label
			this.form.studentSex = e.value[0].id
			this.xbshow = false
		},
		confirmMZ(e){
			this.form.studentNation1 = e.value[0].label
			this.form.studentNation = e.value[0].id
			this.mzshow = false
		},
		getNd(){
			this.ndshow = true
		},
		jdconfirm(e){
			this.queryParams.result1 = e.value[0].label
			this.queryParams.result = e.value[0].id
			this.jdshow = false
			this.getList()
		},
		bmopen() {
		  // console.log('open');
		},
		bmclose() {
		  this.show = false
		  // console.log('close');
		},
		//筛查进度
		getJd(){
			this.jdshow = true
		},
		getScnd(){
			this.scndshow = true
		},
		getScjd(){
			this.scjdshow = true
		},
		//选择部门
		getSC(){
			// this.bmshow = true
			// console.log(11)
			uni.navigateTo({
				url:'/pages/common/deptItem'
			})
		},
		toCj(e){
			uni.navigateTo({
				url:'/pages/slcj/index?code='+e.planNo
			})
		}
	}
  }
</script>
<style lang="scss" scoped>
	.container {
	  background-color: #F2F2F2;
	  min-height: 100vh;
	  padding: 20rpx;
	}
	.serBox{
		display: flex;
		align-items: center;
		margin-bottom: 30rpx;
	}
	.itemBox{
		width: 92%;
		margin: 0 auto;
		background-color: #00ffcc;
		border-radius: 20rpx;
		margin-bottom: 20rpx;
		// display: flex;
		// flex-direction: column;
		padding: 20rpx;
	}
	.submit-button {
		 margin-top: 20rpx;
		 line-height: 100rpx;
		 text-align: center;
		 background: #67e3cb;
		 border-radius: 20rpx;
		 color: #000000;
		 margin-top: 150rpx;
		 font-size: 35rpx;
		 width: 600rpx;
	}
	
</style>
